<?php
namespace app\home\controller;

use app\common\controller\Frontend;
use think\Controller;
use think\Request;
use think\Db;
use fast\lucn\Lucn;

/**
 * about控制器
 * @author  Lucn30 <Lucn30@126.com>
 */

class Product extends Base {
    public function _initialize(){
		parent::_initialize();
		    define('TABLE', 'product');//定义数据表名。
			define('SIGN', 'product');//定义标识
			//define('PID', 2);//定义类别
			$this->assign('controller_sign',SIGN);
			$this->assign('controller_page','产品展示');
			$this->assign('method_sign',SIGN);
	}
    public function tolist(){
        $cid = input('id/d',0);
		/*
		if(input('?id/d')){
		  $arr_id = Lucn::getCate($id,'id',false);
		  $map['a.cid'] = array('IN',implode(',',$arr_id));
		}
		*/
		 if($cid != 0){$map['category_id'] = $cid;}
		  $map2['type'] = SIGN;
		  $list_category = Db::name('Category')
		  ->where($map2)
		  ->field('id,name')
		  ->cache(true)
		  ->select();
		  
		  foreach($list_category as $i => $son){
		      if($son['id'] == $cid){
			      $one_category = $son;
			  }
		  }
		  
		  if(empty($one_category)){
		      $one_category['id'] = 0;
			  $one_category['name'] = '产品中心';
		  }
		
        $map['status'] = 'normal';
		$list = Db::name(TABLE)
        ->where($map)
        /*->distinct(true)*/
        ->field('id,title,description,createtime,image')
		->order('weigh desc')
        ->paginate(6);
		//dump(Db::getLastSql());die;
		$site_title = $one_category['id'] == 0 ? '产品中心'.'_'.$this->cache['site']['name'] : $one_category['name'].'_产品中心'.'_'.$this->cache['site']['name'];
		$this->assign('description','淮阳县金农实业有限公司官方网站，淮王府七芯黄花菜品牌网站。');
		$this->assign('keyword','淮王府七芯黄花菜,淮阳县金农实业有限公司,淮阳黄花菜,速冻黄花菜,淮阳冷链物流');
		$this->assign('title', $site_title);
		$this->assign('list_category',$list_category);
		$this->assign('one_category',$one_category);
		$this->assign('list',$list);
		return $this->Fetch('/home/'.SIGN.'_list');
    }
	
	public function show(){
	    $id = input('id/d',1);

		//$map['status'] = 'normal';
		$map['id'] = $id;
		$one = Db::name(TABLE)
        ->where($map)
        ->find();
		
		  $map2['type'] = SIGN;
		  $list_category = Db::name('Category')
		  ->where($map2)
		  ->field('id,name')
		  ->cache(true)
		  ->select();
		
		$map3['category_id'] = $one['category_id'];
		$map3['id'] = array('NEQ',$one['id']);
		$olist = Db::name(TABLE)
        ->where($map3)
		->field('id,title,image')
		->order('createtime desc')
		->limit(6)
        ->select();
		  
		  foreach($list_category as $i => $son){
		      if($son['id'] == $one['category_id']){
			      $one_category = $son;
			  }
		  }
		$this->assign('title',$one['title'].'_产品中心'.'_'.$this->cache['site']['name']);
		$this->assign('description','淮阳县金农实业有限公司官方网站，淮王府七芯黄花菜品牌网站。');
		$this->assign('keyword','淮王府七芯黄花菜,淮阳县金农实业有限公司,淮阳黄花菜,速冻黄花菜,淮阳冷链物流');
		$this->assign('olist',$olist);
		$this->assign('list_category',$list_category);
		$this->assign('one_category',$one_category);
		$this->assign('one',$one);
        return $this->Fetch('/home/'.SIGN.'_show');
    }
}